package com.etc.service;

import com.etc.dao.HotelDao;
import com.etc.entity.HotelInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelServiceImpl implements HotelService {
    //调用持久层
    @Autowired
    HotelDao dao;

    /**
     * 查询酒店信息
     *
     */
    @Override
    public PageInfo<HotelInfo> getAllHotel(int pageNum, int pageSize,String hotel_name,String hotel_city,String hotel_address)
    {

        //1.开始分页
        PageHelper.startPage(pageNum, pageSize);
        //2.执行查询所有酒店信息
        List<HotelInfo> list =dao.queryAllHotel(hotel_name,hotel_city,hotel_address);
        //3.通过pageInfo进行包装,PageInfo包含了非常丰富的分页属性
        PageInfo<HotelInfo> pageInfo = new PageInfo<HotelInfo>(list);
        return  pageInfo;
    }

    /**
     *
     * 添加酒店信息
     *
     */
    @Override
    public boolean getAddHotel(String hotel_name,String hotel_city,String hotel_address,String hotel_tel) {
        int n=dao.queryAddHotel(hotel_name,hotel_city,hotel_address,hotel_tel);
        return  n>0;
    }

    /**
     * 根据id删除酒店信息
     * @param hotel_id
     * @return
     */
    @Override
    public boolean getUpdateHotel(String hotel_id) {
        int m=dao.queryUpdateHotel(hotel_id);
        return  m>0;
    }

    /**
     * 修改酒店信息
     * @param hotel_name
     * @param hotel_city
     * @param hotel_address
     * @return
     */
    @Override
    public boolean getModHotel(String hotel_id,String hotel_name, String hotel_city, String hotel_address) {
       int x=dao.queryModHotel(hotel_id,hotel_name,hotel_city,hotel_address);
       return x>0;
    }

}
